package com.xn.app.muying.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xn.app.muying.R;
import com.xn.app.muying.bean.HealthRecordsListBean;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/5/8.
 */
public class HealthRecordsHistoryAdapter extends BaseAdapter{
    private final LayoutInflater inflater;
    private Context context;
    private ArrayList<HealthRecordsListBean> list = new ArrayList<>();
    public HealthRecordsHistoryAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void getData(ArrayList<HealthRecordsListBean> data) {
        this.list = data;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.activity_healthrexordshistory_item, null);
            holder = new ViewHolder();
            holder.date_tv = (TextView) convertView.findViewById(R.id.activity_healthrexordshistory_item_date);
            holder.hosptialname_tv = (TextView) convertView.findViewById(R.id.activity_healthrexordshistory_item_hosptialname);
            holder.keshi_tv = (TextView) convertView.findViewById(R.id.activity_healthrexordshistory_item_keshi);
            holder.name_tv = (TextView) convertView.findViewById(R.id.activity_healthrexordshistory_item_name);
            holder.job_tv = (TextView) convertView.findViewById(R.id.activity_healthrexordshistory_item_job);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

            String[] strs = new String[0];
            if (list.get(position).getJzrqsj() != null && !list.get(position).getJzrqsj().equals("") && !list.get(position).getJzrqsj().equals("null")) {
                strs = list.get(position).getJzrqsj().split("T")[0].split("-");
            }

        holder.date_tv.setText(strs[1] + "/" + strs[2] + "\n" + strs[0]);
        if (list.get(position).getHospital() != null && !list.get(position).getHospital().equals("") && !list.get(position).getHospital().equals("null")) {
            holder.hosptialname_tv.setText(list.get(position).getHospital());
        } else {
            holder.hosptialname_tv.setText("");
        }
        if (list.get(position).getJzksmc() != null && !list.get(position).getJzksmc().equals("") && !list.get(position).getJzksmc().equals("null")) {
            holder.keshi_tv.setText(list.get(position).getJzksmc());
        } else {
            holder.keshi_tv.setText("");
        }
        if (list.get(position).getZrys() != null && !list.get(position).getZrys().equals("") && !list.get(position).getZrys().equals("null")) {
            holder.name_tv.setText(list.get(position).getZrys());
        } else {
            holder.name_tv.setText("");
        }
        if (list.get(position).getZryszc() != null && !list.get(position).getZryszc().equals("") && !list.get(position).getZryszc().equals("null")) {
            holder.job_tv.setText(list.get(position).getZryszc());
        } else {
            holder.job_tv.setText("");
        }
        if (list.get(position).getZryszc() != null && !list.get(position).getZryszc().equals("") && !list.get(position).getZryszc().equals("null")) {
            if (holder.job_tv.getVisibility() == View.GONE) {
                holder.job_tv.setVisibility(TextView.VISIBLE);
            }
        }
        return convertView;
    }

    class ViewHolder {
        TextView date_tv, hosptialname_tv, keshi_tv, name_tv, job_tv;
    }
}
